<template>
  <div>
    <el-container>
      <el-form
        label-position="right"
        ref="form"
        :model="form"
        label-width="100px"
      >
        <el-row v-for="(subModule, index) in subModuleList" :key="subModule">{{ subModule }}:
          <el-checkbox-group v-if="index == 0" v-model="form.defining_feature">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group v-if="index == 1" v-model="form.risk_factor">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group v-if="index == 2" v-model="form.evidence">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
        </el-row>
      </el-form>
    </el-container>
  </div>
</template>

<script>
var BaaS = require("minapp-sdk");
let clientID = "9ed0a3da89683e42d793";
BaaS.init(clientID);
export default {
  name: "cardiacCycle",
  props: {
    module_cardiaCycle: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      subModuleList: [
        "定义性特征",
        "危险因素",
        "循证知识"
        ],
      subModuleListSet: new Set(),
      subModuleItemList: [
        [
          "出现第三心音",
          "出现第四心音",
          "肺动脉楔压（PAWP）升高",
          "肺动脉楔压（PAWP）下降",
          "肺血管阻力（PVR）降低",
          "肺血管阻力（PVR）增加",
          "咳嗽",
          "毛细血管再充盈延长",
          "每搏容积指数（SVI）下降",
          "皮肤湿冷",
          "射血分数下降",
          "体重增加",
          "外周动脉搏动减弱",
          "系统血管阻力（SVR）降低",
          "系统血管阻力（SVR）增加",
          "心动过缓",
          "心率改变",
          "心脏杂音",
          "心脏指数下降",
          "中心静脉压（CVP）升高",
          "中心静脉压（CVP）下降",
          "左心室每搏做功指数（LVSWI）下降",
        ],
        ["缺乏出血预防措施的知识"],
        [
          "包皮环切",
          "动脉瘤",
          "肺血管阻力（PVR ）增加",
          "肝功能受损",
          "后负荷改变",
          "每搏容积改变",
          "内在凝血功能障碍",
          "前负荷改变",
          "伸缩力改变",
          "心律改变",
        ],
      ],
      submoduleItemListSet: new Set(),
      form: {
        defining_feature: [],
        risk_factor: [],
        evidence: [],
      },
      formRules: {},
    };
  },
  methods: {
    getSubModuleItem(index1,index2) {
        let itemSet = new Set();
        // this.subModuleItemList[index2] = []; //将当前数组的元素设置为数组就是二维数组了
        let query = new BaaS.Query();
        let overall_eval = new BaaS.TableObject("overall_eval_item");
        query.compare("module", "=", this.module_cardiaCycle);
        query.compare("submodule", "=", this.subModuleList[index2]);
        overall_eval
          .setQuery(query)
          .select(["submodule", "item"])
          .limit(1000)
          .offset(index1)
          .find()
          .then((res) => {
            let datas = res.data.objects;
            datas.forEach((data) => {
              itemSet.add(data.item);
            });
            if (res.data.meta.next !== null) {
              this.getSubModuleItem(index1 + 1000,index2);
            } else {
              this.subModuleItemList.push(Array.from(itemSet));
              console.log(this.subModuleItemList[index2]);
            }
          });
    },
    getSubModule(index) {
      let query = new BaaS.Query();
      let overall_eval = new BaaS.TableObject("overall_eval_item");
      query.compare("module", "=", this.module_cardiaCycle);
      overall_eval
        .setQuery(query)
        .select(["module", "submodule"])
        .limit(1000)
        .offset(index)
        .find()
        .then((res) => {
          let datas = res.data.objects;
          datas.forEach((data) => {
            this.subModuleListSet.add(data.submodule);
          });
          if (res.data.meta.next !== null) {
            this.getSubModule(index + 1000);
          } else {
            this.subModuleList = Array.from(this.subModuleListSet);
            console.log(this.subModuleList);
            for (let i = 0; i < this.subModuleList.length; i++) {
                this.getSubModuleItem(0,i);
            }   
          }
        });
        
    },
    init() {
      this.getSubModule(0);
    },
  },
  mounted() {
    // this.init();
  },
};
</script>

<style>
</style>